<template>
	<view class="padding30">
		<u-form :model="form" ref="uForm" label-width="150" >
				<u-form-item label="收货人"><u-input v-model="form.name" placeholder="请输入收货人姓名"/></u-form-item>
				<u-form-item label="手机号码"><u-input v-model="form.phone" placeholder="请输入手机号码"/></u-form-item>
				<u-form-item label="所在地区">
					<u-input v-model="form.region" placeholder="请选择所在地区" @click='show=true' :disabled='true'/>
				</u-form-item>
				<u-form-item label="详细地址"><u-input v-model="form.addr" placeholder="请输入详细地址，如街道、门派号等"/></u-form-item>
				<view class="mt20 flex col-center">
						<radio color="#FF6B35" :checked="form.is_default==1" @click="change"></radio>
					<text>是否设置为默认地址</text>
				</view>
		</u-form>
		<!-- //省市区 -->
		<u-picker v-model="show" mode="region" @confirm='confirm'></u-picker>
		<!-- 底部按钮 -->
		<view class="fw-500 footerBtn pl30 pr30 bg-f pt20 pb70">
			<u-button type="primary" shape="circle" @click="submit">确认</u-button>
		</view>
	</view>
</template>

<script>
	export default {
		name:'addressD',
		onLoad(opt) {
			if(opt.id) {
				this.id=opt.id
				uni.setNavigationBarTitle({
					title:'编辑地址'
				})
				this.form=uni.getStorageSync('address')
			}else {
				uni.setNavigationBarTitle({
					title:'新增地址'
				})
			}
		},
		data() {
			return {
				//有id是编辑地址  没有id是新增地址
				id:'',
				form:{
					name:'',
					phone:'',
					//省市区
					region:'',
					addr:'',
					is_default:0
				},
				addDetail:'',
				show:false,
			};
		},
		methods: {
			//是否默认地址
			change() {
				// console.log(1)
				this.form.is_default==0 ? this.form.is_default=1 : this.form.is_default=0
				console.log(this.form.is_default)
			},
			//选择地区
			confirm(e) {
				console.log(e)
				this.form.region=e.province.label+'-'+e.city.label+'-'+e.area.label
			},
			//提交
			submit() {
				let api=''
				if(this.id) {
					api='editAddress'
					this.form.id=this.id
					delete this.form.modify_region
					delete this.form.create_time
					delete this.form.update_time
					delete this.form.time
				}else {
					api='addAddress'
				}
				this.$api[api](this.form).then(res=>{
					console.log(res)
					this.$msg(res.msg)
					setTimeout(()=>{
						uni.navigateBack({
							
						})
					},800)
				})
			}
		}
	}
</script>

<style lang="scss">
page {
	background-color: #FFFFFF;
}
</style>
